# ！/usr/bin/env python
# -*- coding = utf-8 -*-
# ================================================
# @Time  :2021/8/5 11:51
# @Author:tyh
# @File  :execute_tools.py
# @Phone :13926528314
# ================================================
from jenkinsapi.jenkins import Jenkins


class ExcuteTools:
    BASE_URL = "http://42.192.73.147:7080/"
    USER_NAME = "jenkins"
    PASS_WORD = "11c6d135dd20efabf04b0edef60266aa41"

    def __init__(self):
        self.base_url = "http://42.192.73.147:7080/"
        self.user_name = "jenkins"
        self.pass_word = "11c6d135dd20efabf04b0edef60266aa41"
        self.jenkins = Jenkins(self.base_url, self.user_name, self.pass_word)

    def get_jobs(self):
        return self.jenkins.keys()

    def invoke(self, task="python"):
        job_name = "WEB_Ci_START"
        job_1 = self.jenkins.get_job(job_name)
        job_1.invoke(build_params={"task": task})
        # http://42.192.73.147:7080/job/WEB_Ci_START/21/allure/
        job_number = job_1.get_last_buildnumber()
        allure_dir = f"{self.base_url}job/{job_name}/{job_number + 1}/allure/"
        return allure_dir


execute_tools = ExcuteTools()